package com.sgcc.platforminterface;


import android.net.Uri;
import android.os.Environment;
import android.os.RemoteException;
import android.text.TextUtils;

import com.sgcc.pda.data.dao.SharepreferenceUtil;
import com.sgcc.pda.hzaidl.IHZAidlCallback;
import com.sgcc.pda.hzaidl.impl.SpeedWebUtil;
import com.sgcc.pda.tools.LogPrintUtils;
import com.sgcc.pda.util.PlatConstant;
import com.sgcc.pda.web.IDownloadListener;
import com.sgcc.pda.web.IUploadListener;
import com.sgcc.pda.web.OrigWebUtil;
import com.sgcc.pda.web.OrigWebUtil2;
import com.sgcc.pda.web.receiver.HttpCallback;
import com.sgcc.pda.web.receiver.HttpReceiver;
import com.sgcc.pda.web.receiver.IWebCall;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @创建者：suven on 2020/3/25 13:51
 * @描述：网络服务
 * @版本：1.0
 * @修改人：
 * @修改时间：
 * @修改说明：
 * @修改版本：
 */
public class HttpManager {


    public static final String APP_PATH = Environment.getExternalStorageDirectory()
            + "/Android/data/com.sgcc.pda.mdrh/files";
    // 主应用或基础服务下载文件的目录
    public static final String DOWNLOAD_PATH = APP_PATH + "/download/";

    /**
     * Post请求，对应老版本postData/postDataCallback
     *
     * @param serverName    服务名
     * @param cmdName       接口名
     * @param requestParams 请求参数
     * @param iWebCall      回调
     * @throws RemoteException 异常返回
     */
    public static void call(String serverName, String cmdName, Map<String, String> requestParams, IWebCall iWebCall) throws RemoteException {
        call(serverName, PlatConstant.IWeb.REQ_HTTP, cmdName, requestParams, iWebCall);
    }

    /**
     * Post请求，对应老版本postData/postDataCallback
     *
     * @param serverName    服务名
     * @param cmdName       接口名
     * @param requestParams 请求参数
     * @param appendUid     是否拼接uid
     * @param iWebCall      回调
     * @throws RemoteException 异常返回
     */
    public static void call(String serverName, String cmdName, Map<String, String> requestParams, boolean appendUid, IWebCall iWebCall) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            SpeedWebUtil.postData(serverName, PlatConstant.IWeb.REQ_HTTP, cmdName, requestParams, appendUid, iWebCall);
        } else {
            OrigWebUtil.postData(serverName, PlatConstant.IWeb.REQ_HTTP, cmdName, requestParams, onReceiverCallBack(iWebCall), appendUid);
        }
    }

    /**
     * Post请求
     *
     * @param serverName    服务名
     * @param methodName    方法名
     * @param cmdName       接口名（包含路径）
     * @param requestParams 请求参数
     * @param iWebCall      回调
     * @throws RemoteException 异常返回
     */
    public static void call(String serverName, String methodName, String cmdName, Map<String, String> requestParams, IWebCall iWebCall) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            SpeedWebUtil.postData(serverName, methodName, cmdName, requestParams, iWebCall);
        } else {
            OrigWebUtil.postData(serverName, methodName, cmdName, requestParams, onReceiverCallBack(iWebCall));
        }
    }

    /**
     * 参数+文件请求
     * 对应支持老版接口
     * saveGQH/setModuleInfo/setModuleInfoNew/saveSBZC/uploadPramsAndImages/setModuleInfo2
     * postData/postDataCallback
     *
     * @param serverName    服务名
     * @param cmdName       接口名（包含路径）
     * @param requestParams 参数
     * @param files         文件列表
     * @param iWebCall      回调
     * @throws RemoteException 异常返回
     */
    public static void call(String serverName, String cmdName, Map<String, String> requestParams, List<File> files, IWebCall iWebCall) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            SpeedWebUtil.uploadPramsAndFiles(serverName, cmdName, requestParams, files, iWebCall);
        } else {
            OrigWebUtil.uploadPramsAndImages(serverName, cmdName, requestParams, files, onReceiverCallBack(iWebCall));
        }
    }

    /**
     * 参数+文件请求
     * 对应支持老版接口
     * saveGQH/setModuleInfo/setModuleInfoNew/saveSBZC/uploadPramsAndImages/setModuleInfo2
     * postData/postDataCallback
     *
     * @param serverName    服务名
     * @param cmdName       接口名（包含路径）
     * @param requestParams 参数
     * @param files         文件列表
     * @param appendUid     是否拼接Uid
     * @param iWebCall      回调
     * @throws RemoteException 异常返回
     */
    public static void call(String serverName, String cmdName, Map<String, String> requestParams, List<File> files, boolean appendUid, IWebCall iWebCall) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            SpeedWebUtil.uploadPramsAndFiles(serverName, cmdName, requestParams, files, appendUid, iWebCall);
        } else {
            OrigWebUtil.uploadPramsAndImages(serverName, cmdName, requestParams, files, onReceiverCallBack(iWebCall));
        }
    }

    /**
     * 上传图片 对应老接口upFileImg
     *
     * @param app_no   工单编号
     * @param app_type 工单类型
     * @param imgs     图片信息
     * @param files    图片列表
     * @param iWebCall 回调
     * @throws RemoteException 异常返回
     */
    public static void uploadImg(String app_no,
                                 String app_type, String imgs, List<File> files, IWebCall iWebCall) throws
            RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            SpeedWebUtil.uploadImg(app_no, app_type, imgs, files, iWebCall);
        } else {
            OrigWebUtil.upFileImg(app_no, app_type, imgs, files, onReceiverCallBack(iWebCall));
        }
    }

    /**
     * 上传图片 对应老接口upFileImg2
     *
     * @param app_no   工单编号
     * @param app_type 工单类型
     * @param imgs     图片信息
     * @param files    图片列表
     * @param iWebCall 回调
     * @throws RemoteException 异常返回
     */
    public static void upFileImg2(String app_no, String app_type, String imgs, List<File> files, IWebCall iWebCall) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            SpeedWebUtil.uploadImg(app_no, app_type, imgs, files, iWebCall);
        } else {
            OrigWebUtil.upFileImg2(app_no, app_type, imgs, SpeedWebUtil.onFilesToString(files), onReceiverCallBack(iWebCall));
        }
    }


    /**
     * 文件下载
     *
     * @param serverName    服务名
     * @param cmdName       方法名
     * @param requestParams 请求参数
     * @param filePath      保存路+文件名
     * @param fileName      文件名
     * @param iWebCall      回调
     * @throws RemoteException 异常返回
     */
    public static void download(String serverName, String cmdName, Map<String, String> requestParams, String filePath, String fileName, IWebCall iWebCall) throws RemoteException {
        download(PlatConstant.IWeb.REQ_HTTP_FILE_DOWN, serverName, cmdName, requestParams, filePath, fileName, iWebCall);
    }

    /**
     * 文件下载
     *
     * @param methodName    方法名
     * @param serverName    服务名
     * @param cmdName       方法名
     * @param requestParams 请求参数
     * @param filePath      保存路+文件名
     * @param fileName      文件名
     * @param iWebCall      回调
     * @throws RemoteException 异常返回
     */
    public static void download(String methodName, String serverName, String cmdName, Map<String, String> requestParams, String filePath, String fileName, IWebCall iWebCall) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            SpeedWebUtil.download(methodName, serverName, cmdName, requestParams, filePath, fileName, iWebCall);
        } else {
            if (TextUtils.isEmpty(filePath)) {
                filePath = DOWNLOAD_PATH + fileName;
            }
            OrigWebUtil.downloadFile(SpeedWebUtil.getDownloadUrl(methodName, serverName, cmdName, requestParams), filePath, onReceiverCallBack(iWebCall, true));
        }
    }

    /**
     * 下载图文，对应老接口downloadComm
     *
     * @param serverName 服务名
     * @param cmdName    方法名
     * @param fileId     文件编号
     * @param fileName   文件名
     * @param iWebCall   回调
     * @throws RemoteException 异常返回
     */
    public static void downloadComm(
            String serverName, String cmdName, String fileId, String fileName, IWebCall iWebCall) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            Map<String, String> requestParams = new HashMap<>();
            requestParams.put("FID_NO", fileId);
            String fName = fileName.substring(fileName.lastIndexOf("."), fileName.length());
            String fileLocPath = DOWNLOAD_PATH + fileId + fName;
            SpeedWebUtil.download(serverName, cmdName, requestParams, fileLocPath, fileName, iWebCall);
        } else {
            OrigWebUtil.downloadComm(1, serverName, cmdName, fileId, fileName, onReceiverCallBack(iWebCall, true));
        }
    }


    /**
     * 文件下载，对应老版本 downloadFile2，下载方式使用1，显示过程
     *
     * @param serverName 服务名
     * @param fileId     文件编号
     * @param fileName   文件名
     * @param iWebCall   回调
     * @throws RemoteException 异常返回
     */
    public static void downloadFile2(String serverName, String fileId, String fileName, IWebCall iWebCall) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            Map<String, String> requestParams = new HashMap<>();
            requestParams.put("FID_NO", fileId);
            String fName = fileName.substring(fileName.lastIndexOf("."), fileName.length());
            String fileLocPath = DOWNLOAD_PATH + fileId + fName;
            SpeedWebUtil.download(serverName, "appDownload", requestParams, fileLocPath, fileName, iWebCall);
        } else {
            OrigWebUtil.downloadFile2(1, serverName, fileId, fileName, onReceiverCallBack(iWebCall, true));
        }
    }

    /**
     * 直接调用URL 对应老版本requestCustomerUrl，极速版不开放
     *
     * @param url      地址
     * @param iWebCall 回调
     * @throws RemoteException 异常返回
     */
    public static void requestCustomerUrl(String url, IWebCall iWebCall) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            if (iWebCall != null)
                iWebCall.onFail(PlatConstant.IWebState.error, "不支持此方法");
        } else {
            OrigWebUtil.requestCustomerUrl(onReceiverCallBack(iWebCall), url);
        }
    }

    /**
     * 订阅一个主题，后台根据主题推送消息
     */
    public static boolean subscribe(String packageName, String topic) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            return SpeedWebUtil.subscribe(packageName, topic);
        } else {
            return OrigWebUtil.subscribe(packageName, topic);
        }
    }

    /**
     * 向对应的主题，发布一条消息。
     * topic  主题名
     * content 发布的内容
     */
    public static boolean publish(String topic, String content) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            return SpeedWebUtil.publish(topic, content);
        } else {
            return OrigWebUtil.publish(topic, content);
        }
    }

    /**
     * 取消订阅一个主题
     */
    public static boolean unsubscribe(String packageName, String topic) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            return SpeedWebUtil.unsubscribe(packageName, topic);
        } else {
            return OrigWebUtil.unsubscribe(packageName, topic);
        }
    }

    /**
     * 获取离线消息
     * packageName 包名
     */
    public static String getOfflineMsg(String packageName) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            return SpeedWebUtil.getOfflineMsg(packageName);
        } else {
            return OrigWebUtil.getOfflineMsg(packageName);
        }
    }


    /**
     * 上报已收到消息
     *
     * @param packageName 包名
     * @param time        时间戳tag
     * @return
     * @throws RemoteException
     */
    public static boolean reportReceivedMsg(String packageName, String time) throws
            RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            return SpeedWebUtil.reportReceivedMsg(packageName, time);
        } else {
            return OrigWebUtil.reportReceivedMsg(packageName, time);
        }
    }

    /**
     * 大文件上传
     *
     * @param filePath 上传文件路径
     * @param savePath 服务器保存路径
     * @param isDelete 是否删除
     * @param iWebCall
     * @throws RemoteException
     */
    public static void blockUploadFile(String filePath, String savePath, boolean isDelete, final IWebCall iWebCall)
            throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            SpeedWebUtil.blockUploadFile(filePath, savePath, isDelete, iWebCall);
        } else {
            OrigWebUtil.blockUploadFile(filePath, savePath, isDelete, new IUploadListener.Stub() {
                @Override
                public void result(boolean isSuccess, String msg) throws RemoteException {
                    if (isSuccess)
                        iWebCall.onSuccess(msg);
                    else
                        iWebCall.onFail("", msg);
                }

                @Override
                public void progress(int current, int total, int status) throws RemoteException {
                    iWebCall.onDownLoading(current, total, status);
                }
            });
        }

    }


    /**
     * 取消大文件上传
     *
     * @param filePath 上传文件路径
     * @param savePath 服务器保存路径
     * @param iWebCall
     * @throws RemoteException
     */
    protected static void cancelBlockUploadFile(String filePath, String savePath, final IWebCall iWebCall)
            throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            SpeedWebUtil.cancelBlockUploadFile(filePath, savePath, iWebCall);
        } else {
            OrigWebUtil.cancelBlockUploadFile(filePath, savePath, onCallBack(iWebCall));
        }
    }

    /**
     * 参数查询接口
     *
     * @param appIdentity  应用标识(APP包名或其它标识)
     * @param paramVersion 参数版本号
     * @param iWebCall     请求数据的回调
     */
    public static void getParamQuery(String appIdentity, String paramVersion, IWebCall iWebCall)
            throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            SpeedWebUtil.getParamQuery(appIdentity, paramVersion, iWebCall);
        } else {
            OrigWebUtil.getParamQuery(appIdentity, paramVersion, onCallBack(iWebCall));
        }
    }

    /**
     * 文件下载接口(支持多种文件，断点续传)
     * @param filePath           图片在服务端的路径
     * @param savePath           图片在本地保存的路径
     * @param listener  请求数据的回调
     */
    public static void downloadPicFile(String filePath, String savePath, IDownloadListener listener)
            throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            SpeedWebUtil.downPicFile(filePath, savePath, new IHZAidlCallback.Stub() {
                @Override
                public void callback(String result) throws RemoteException {
//                    listener.onSuccess(result);
                }
            });
        } else {
            OrigWebUtil.downloadPicFile(filePath, savePath, listener);
        }
    }


    /**
     * 末端方法，对应 saveGQH
     *
     * @param meetingId id
     * @param orderIds  工单ids
     * @param files     文件路径
     * @param iWebCall  回调
     * @throws RemoteException 错误
     */
    public static void saveGQH(String meetingId, String orderIds, List<File> files, IWebCall iWebCall) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            Map<String, String> requestParams = new HashMap<>();
            requestParams.put("userId", SharepreferenceUtil.getUserCode(PlatfInterfManager.getInstance().getContext()));
            requestParams.put("meetingId", meetingId);
            requestParams.put("orderIds", orderIds);
            requestParams.put("orgNo", SharepreferenceUtil.getOrgCode(PlatfInterfManager.getInstance().getContext()));
            requestParams.put("deptId", SharepreferenceUtil.getDeptCode(PlatfInterfManager.getInstance().getContext()));
            requestParams.put("WT_DEPT", "hehehehe");
            call("mdrhWorkServer", "saveWorkMeeting.do", requestParams, files, iWebCall);
        } else {
            OrigWebUtil.saveGQH(meetingId, orderIds, SpeedWebUtil.onFilesToString(files), onReceiverCallBack(iWebCall));
        }
    }

    /**
     * 保存模块信息 末端方法，对应 setModuleInfo
     *
     * @param iWebCall             回调
     * @param assetNo              设备资产编号
     * @param deviceType           设备类型
     * @param oldModuleNum         旧模块厂商名称
     * @param oldModuleTypeNo      旧模块类型编号
     * @param oldModuleFactoryName 旧模块编号
     * @param newModuleFactoryNo   新模块厂商编号
     * @param newModuleFactoryName 新模块厂商名称
     * @param newModuleNum         新模块编号
     * @param reason               更换原因
     * @param files                更换图示集合
     * @param testResult           召测结果
     * @param operUSERNO           更换人
     * @param operDT               更换时间
     * @throws RemoteException 错误
     */
    protected static void setModuleInfo(String assetNo, String deviceType, String oldModuleNum,
                                        String oldModuleTypeNo, String oldModuleFactoryName,
                                        String newModuleTypeNo, String newModuleFactoryNo,
                                        String newModuleFactoryName, String newModuleNum, String reason,
                                        List<File> files, String testResult, String operUSERNO,
                                        String operDT, IWebCall iWebCall) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            Map<String, String> requestParams = new HashMap<>();
            requestParams.put("assetNo", assetNo);
            requestParams.put("deviceType", deviceType);
            requestParams.put("oldModuleNum", oldModuleNum);
            requestParams.put("oldModuleTypeNo", oldModuleTypeNo);
            requestParams.put("oldModuleFactoryName", oldModuleFactoryName);
            requestParams.put("newModuleTypeNo", newModuleTypeNo);
            requestParams.put("newModuleFactoryName", newModuleFactoryName);
            requestParams.put("newModuleNum", newModuleNum);
            requestParams.put("newModuleFactoryNo", newModuleFactoryNo);
            requestParams.put("reason", reason);
            requestParams.put("testResult", testResult);
            requestParams.put("operUSERNO", operUSERNO);
            requestParams.put("operDT", operDT);
            call("mkghserver", "setModuleInfo.do", requestParams, files, iWebCall);
        } else {
            OrigWebUtil.setModuleInfo(assetNo, deviceType, oldModuleNum, oldModuleTypeNo,
                    oldModuleFactoryName, newModuleTypeNo, newModuleFactoryNo,
                    newModuleFactoryName, newModuleNum, reason,
                    SpeedWebUtil.onFilesToString(files), testResult,
                    operUSERNO, operDT, onReceiverCallBack(iWebCall));
        }
    }

    /**
     * 保存模块信息  末端方法，对应 setModuleInfoNew
     *
     * @param iWebCall             回调
     * @param assetNo              设备资产编号
     * @param deviceType           设备类型
     * @param oldModuleNum         旧模块厂商名称
     * @param oldModuleTypeNo      旧模块类型编号
     * @param oldModuleFactoryName 旧模块编号
     * @param newModuleFactoryNo   新模块厂商编号
     * @param newModuleFactoryName 新模块厂商名称
     * @param newModuleNum         新模块编号
     * @param reason               更换原因
     * @param files                更换图示集合
     * @param testResult           召测结果
     * @param operUSERNO           更换人
     * @param operDT               更换时间
     * @throws RemoteException 错误
     */
    protected static void setModuleInfoNew(String assetNo, String deviceType, String oldModuleNum, String oldModuleTypeNo, String oldModuleFactoryName,
                                           String newModuleTypeNo, String newModuleFactoryNo, String newModuleFactoryName,
                                           String newModuleNum, String reason, List<File> files, String testResult, String operUSERNO, String operDT, IWebCall iWebCall) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            Map<String, String> requestParams = new HashMap<>();
            requestParams.put("assetNo", assetNo);
            requestParams.put("deviceType", deviceType);
            requestParams.put("oldModuleNum", oldModuleNum);
            requestParams.put("oldModuleTypeNo", oldModuleTypeNo);
            requestParams.put("oldModuleFactoryName", oldModuleFactoryName);
            requestParams.put("newModuleTypeNo", newModuleTypeNo);
            requestParams.put("newModuleFactoryName", newModuleFactoryName);
            requestParams.put("newModuleNum", newModuleNum);
            requestParams.put("newModuleFactoryNo", newModuleFactoryNo);
            requestParams.put("reason", reason);
            requestParams.put("testResult", testResult);
            requestParams.put("operUSERNO", operUSERNO);
            requestParams.put("operDT", operDT);
            call("mkghserver", "setModuleInfo.do", requestParams, files, iWebCall);
        } else {
            OrigWebUtil.setModuleInfoNew(assetNo, deviceType, oldModuleNum, oldModuleTypeNo,
                    oldModuleFactoryName, newModuleTypeNo, newModuleFactoryNo,
                    newModuleFactoryName, newModuleNum, reason, SpeedWebUtil.onFilesToString(files),
                    testResult, operUSERNO, operDT, onReceiverCallBack(iWebCall));
        }
    }


    /**
     * 保存单户装拆文件和数据 末端方法，对应 saveSBZC
     *
     * @param iWebCall      回调
     * @param cmdName       方法名
     * @param requestParams 参数集
     * @param files         文信息
     * @throws RemoteException 错误
     */
    protected static void saveSBZC(String cmdName, Map<String, String> requestParams, List<File> files, IWebCall iWebCall) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            SpeedWebUtil.uploadPramsAndFiles("sbzcserver", cmdName, requestParams, files, iWebCall);
        } else {
            Uri.Builder builder = Uri.parse(cmdName).buildUpon();
            for (String key : requestParams.keySet()) {
                builder.appendQueryParameter(key, requestParams.get(key));
            }
            LogPrintUtils.d("入参：", builder.toString());
            OrigWebUtil.saveSBZC(builder.toString(), SpeedWebUtil.onFilesToString(files), onReceiverCallBack(iWebCall));
        }
    }

    /**
     * 保存模块信息 末端方法，对应 setModuleInfo2
     *
     * @param iWebCall             回调
     * @param assetNo              设备资产编号
     * @param deviceType           设备类型
     * @param oldModuleNum         旧模块厂商名称
     * @param oldModuleTypeNo      旧模块类型编号
     * @param oldModuleFactoryName 旧模块编号
     * @param newModuleFactoryNo   新模块厂商编号
     * @param newModuleFactoryName 新模块厂商名称
     * @param newModuleNum         新模块编号
     * @param reason               更换原因
     * @param files                更换图示集合
     * @param testResult           召测结果
     * @param operUSERNO           更换人
     * @param operDT               更换时间
     * @throws RemoteException 错误
     */
    public static void setModuleInfo2(IWebCall iWebCall, String assetNo, String deviceType, String oldModuleNum,
                                      String oldModuleTypeNo, String oldModuleFactoryName, String newModuleTypeNo, String newModuleFactoryNo,
                                      String newModuleFactoryName, String newModuleNum, String reason,
                                      List<File> files, String testResult,
                                      String operUSERNO, String operDT) throws RemoteException {
        if (PlatfInterfManager.getInstance().isSpeed()) {
            try {
                oldModuleFactoryName = URLEncoder.encode(oldModuleFactoryName, "UTF-8");
                newModuleFactoryName = URLEncoder.encode(newModuleFactoryName, "UTF-8");
                operUSERNO = URLEncoder.encode(operUSERNO, "UTF-8");
                reason = URLEncoder.encode(reason, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }

            Map<String, String> requestParams = new HashMap<>();
            requestParams.put("assetNo", assetNo);
            requestParams.put("deviceType", deviceType);
            requestParams.put("oldModuleNum", oldModuleNum);
            requestParams.put("oldModuleTypeNo", oldModuleTypeNo);
            requestParams.put("oldModuleFactoryName", oldModuleFactoryName);
            requestParams.put("newModuleTypeNo", newModuleTypeNo);
            requestParams.put("newModuleFactoryName", newModuleFactoryName);
            requestParams.put("newModuleNum", newModuleNum);
            requestParams.put("newModuleFactoryNo", newModuleFactoryNo);
            requestParams.put("reason", reason);
            requestParams.put("testResult", testResult);
            requestParams.put("operUSERNO", operUSERNO);
            // requestParams.put("operDT", operDT);
            call("mkghserver", "setModuleInfo.do", requestParams, files, iWebCall);
        } else {
            OrigWebUtil2.setModuleInfo2(onReceiverCallBack(iWebCall), assetNo, deviceType, oldModuleNum,
                    oldModuleTypeNo, oldModuleFactoryName, newModuleTypeNo, newModuleFactoryNo,
                    newModuleFactoryName, newModuleNum, reason, SpeedWebUtil.onFilesToString(files), testResult,
                    operUSERNO, operDT);
        }
    }


    //接口回调反回统一
    private static HttpCallback onCallBack(final IWebCall iWebCall) {
        return onCallBack(iWebCall, false);
    }

    private static HttpCallback onCallBack(final IWebCall iWebCall, final boolean downLoad) {
        return new HttpCallback(iWebCall.getContext()) {

            @Override
            public void onISuccess(String response) {
                iWebCall.onSuccess(response);
            }

            @Override
            public void onIFail(String code, String message) {
                iWebCall.onFail(code, message);
            }

            @Override
            public boolean isDownLoad() {
                return downLoad;
            }

        };
    }


    //广播返回结果统一
    private static String onReceiverCallBack(final IWebCall iWebCall) {
        return onReceiverCallBack(iWebCall, false);
    }

    private static String onReceiverCallBack(final IWebCall iWebCall, final boolean downLoad) {
        HttpReceiver h = new HttpReceiver(iWebCall.getContext()) {

            @Override
            public void onISuccess(String response) {
                iWebCall.onSuccess(response);
            }

            @Override
            public void onIFail(String code, String message) {
                iWebCall.onFail(code, message);
            }

            @Override
            public void onIDownLoading(int progress) {
                iWebCall.onDownLoading(progress);
            }

            @Override
            public boolean isDownLoad() {
                return downLoad;
            }
        };
        return h.getTag();
    }
}
